/*
 * PrevAction.java
 *
 * Created on June 22, 2005, 7:37 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */
package com.bff.slimserver.musicjukebox.lib.actions;

import com.bff.slimserver.music.exceptions.PlaylistException;
import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.slimserver.musicjukebox.lib.events.PlayerChosenEvent;
import com.bff.slimserver.musicjukebox.lib.events.PlayerChosenListener;
import com.bff.bjj.utils.Resources;
import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import org.bff.slimserver.SlimPlaylist;
import org.bff.slimserver.exception.SlimException;

/**
 *
 * @author Bill
 */
public class PrevAction extends PlaylistAction {

    /** Creates a new instance of StopAction */
    public PrevAction(SlimPlaylist playlist) {
        super(playlist);

        putValue(Action.NAME, Resources.getMessage(Resources.LABEL_KEY.ACTION_PREVIOUS_NAME));
        putValue(Action.SMALL_ICON, Resources.getIcon(Resources.ICON_KEY.ACTION_PREVIOUS));
        putValue(Action.MNEMONIC_KEY, Resources.getKeyEvent(Resources.KEYEVENT_KEY.ACTION_PREVIOUS));
        putValue(Action.ACCELERATOR_KEY, Resources.getKeystroke(Resources.KEYSTROKE_KEY.KEYSTROKE_PREVIOUS));
        putValue(Action.SHORT_DESCRIPTION, Resources.getMessage(Resources.LABEL_KEY.ACTION_PREVIOUS_SHORT_DESC));
    }

    @Override
    public void actionPerformed(ActionEvent evt) {
        try {
            if (JukeboxProperties.getInstance().getPlayer().getElapsedTime() < 3) {
                getPlaylist().playPrevious();
            } else {
                getPlaylist().playItem(getPlaylist().getCurrentItem());
            }
        } catch (SlimException ex) {
            Logger.getLogger(PrevAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}